<?php
/**
 * File: AddMember.class.php
 * Author: camy <375766145@qq.com>
 * Time: 2018/3/22 09:12
 */

namespace Common\Extend\DingTalk\Message\Project;

use Common\Extend\DingTalk\Message\BaseMessage;

class AddMember extends BaseMessage
{
    public function send($param)
    {
        //标题
        $this->title = '项目提醒';
        //跳转地址
        $this->setUrl('project/detail', ['id' => $param['project_id']]);
        //发送人
        $people = $this->getUserId($param['user_id']);
        //成员类型
        $type = M('projectMember')
            ->where(['project_id' => $param['project_id'], 'user_id' => $param['user_id']])
            ->getField('user_type');
        if ($type == 1) {
            $typeName = '专业负责人';
        } else {
            $typeName = '项目成员';
        }

        //发送内容
        $projectName = M('project')
            ->where(['id' => intval($param['project_id'])])
            ->getField('name');
        $text = "你被设为【{$projectName}】" . $typeName;
        $message = $this->getMessage($text);
        //发送消息
        dingtalk()->sendMessage($people, $message);
    }
}